package com.eccg.shopping.activity;

import java.util.ArrayList;
import java.util.List;

import com.eccg.shopping.R;
import com.eccg.shopping.activity.StoreActivity.PromotionAdapter;
import com.eccg.shopping.utils.PageView;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ImageView.ScaleType;

public class DaoGouActivity extends BaseActivity {
	
	private Gallery daogou_gallery;
	private PageView daogou_pageview;

	private LinearLayout daogou_loucenglist_ll;
	private LinearLayout daogou_storelist_ll;
	private LinearLayout daogou_contentlist_ll;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		initHeader();
		setContentView(R.layout.daogou);

		daogou_loucenglist_ll = (LinearLayout) findViewById(R.daogou.daogou_loucenglist_ll);
		daogou_storelist_ll = (LinearLayout) findViewById(R.daogou.daogou_storelist_ll);
		daogou_contentlist_ll = (LinearLayout) findViewById(R.daogou.daogou_contentlist_ll);
		
		daogou_gallery = (Gallery) findViewById(R.daogou.daogou_gallery);
		daogou_pageview = (PageView) findViewById(R.daogou.daogou_pageview);
		
		ArrayList<String> lists = getStrings();
		
		if(lists != null && lists.size() > 0){
			daogou_pageview.setTotalPage(lists.size());
			daogou_pageview.setCurrentPage(0);
		}
		
		PromotionAdapter promotionAdapter = new PromotionAdapter(DaoGouActivity.this, R.layout.promotion_item, R.promotion_item.promotion_item_tv, lists);
		daogou_gallery.setAdapter(promotionAdapter);
		daogou_gallery.setFadingEdgeLength(0);
		daogou_gallery.setSpacing(5);
		daogou_gallery.setOnItemSelectedListener(new OnItemSelectedListener() {
			@Override
			public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
				daogou_pageview.setCurrentPage(position);
			}

			@Override
			public void onNothingSelected(AdapterView<?> parent) {
			}
		});
		

		daogou_storelist_ll.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(DaoGouActivity.this, StoreSelectActivity.class);
				DaoGouActivity.this.startActivity(intent);
			}
		});

		daogou_loucenglist_ll.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				Intent intent = new Intent();
				intent.setClass(DaoGouActivity.this, FloorListActivity.class);
				DaoGouActivity.this.startActivity(intent);
			}
		});
		daogou_contentlist_ll.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {

			}
		});
	}

	@Override
	protected void initHeader() {
		// TODO Auto-generated method stub
		super.initHeader();
		titleTx.setText("导购");
	}

	@Override
	protected int getMenuIndex() {
		// TODO Auto-generated method stub
		return DAOGOUINDEX;
	}
	
	class PromotionAdapter extends ArrayAdapter<String> {

		public PromotionAdapter(Context context, int resource, int textViewResourceId, List<String> objects) {
			super(context, resource, textViewResourceId, objects);
		}
		@Override
		public View getView(int position, View convertView, ViewGroup parent) {
			if (convertView == null) {
				LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
				convertView = inflater.inflate(R.layout.promotion_item, null);
			}
			ImageView imageView = (ImageView) convertView.findViewById(R.promotion_item.promotion_item_iv);
			imageView.setImageResource(R.drawable.image_size);
			imageView.setScaleType(ScaleType.FIT_XY);
			return convertView;
		}
	}
	
	private ArrayList<String> getStrings() {
		ArrayList<String> lists = new ArrayList<String>();
		lists.add("夏季长衫你会穿吗");
		lists.add("夏季长衫你会穿吗");
		lists.add("夏季长衫你会穿吗");
		lists.add("夏季长衫你会穿吗");
		lists.add("夏季长衫你会穿吗");
		lists.add("夏季长衫你会穿吗");
		lists.add("夏季长衫你会穿吗");
		lists.add("夏季长衫你会穿吗");
		lists.add("夏季长衫你会穿吗");
		lists.add("夏季长衫你会穿吗");
		return lists;
	}

}
